<?php
use \yii\helpers\Url;

$this->title = '编辑角色权限';
$this->params['breadcrumbs'][] = ['label' => '角色列表', 'url' => ['roles']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="form-group">
    <div class="col-md-12">
        <h5><span class="color-view font-blue bold uppercase"><?=$roleName?></span>权限管理</h5>
    </div>
    <div class="col-md-12">
        <select multiple="multiple" class="multi-select form-control" id="my_multi_select">
            <?php foreach ($permissions as $perm) {?>
                <option <?=in_array($perm->name, $existPermissions) ? 'selected' : ''?> value="<?=$perm->name?>"><?=$perm->description?></option>
            <?php }?>
        </select>
    </div>
</div>
<style>
    .ms-container{width:450px;}
    .ms-container .ms-list{height: 290px;}
</style>
<?=
$this->registerCssFile('metronic/theme/assets/global/plugins/jquery-multi-select/css/multi-select.css', [ 'depends' => 'backend\assets\AppAsset']);
$this->registerJsFile('metronic/theme/assets/global/plugins/bootstrap-select/js/bootstrap-select.min.js', ['depends' => 'backend\assets\AppAsset']);
$this->registerJsFile('metronic/theme/assets/global/plugins/jquery-multi-select/js/jquery.multi-select.js', ['depends' => 'backend\assets\AppAsset']);
$this->registerJsFile('/static/pages/js/list.js', [ 'depends' => 'backend\assets\AppAsset']);

$this->registerJs('
    jQuery(document).ready(function() {
        var isLoading = false;
        $(\'#my_multi_select\').multiSelect({
             afterSelect: function(values){
                if(isLoading) {
                    return false;
                }
                isLoading = true;
                Common.postAjaxRequest("'.Url::to(['/auth/ajaxroleperm']).'",{rolename:"'.$roleName.'",permname: values[0],action:\'select\'}, function(){
                    isLoading = false;
                });
             },
             afterDeselect: function(values){
                if(isLoading) {
                    return false;
                }
                isLoading = true;
                Common.postAjaxRequest("'.Url::to(['/auth/ajaxroleperm']).'",{rolename:"'.$roleName.'",permname: values[0],action:\'deselect\'}, function(){
                    isLoading = false;
                });
             }
          });
    });
',$this::POS_END);
?>